﻿@using admin.Model
@{
    ViewData["Title"] = "BookFor";
    Layout = "~/Views/Shared/_SubMenuLayout.cshtml";
    var manuscript = Model as List<Fileview>;
}

<title>文稿列表</title>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 作者管理 <span class="c-gray en">&gt;</span> 出书申请 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
    <div class="cl pd-5 bg-1 bk-gray mt-20">
        <span class="l">
            <a href="javascript:;" onclick="article_batch_del('/Home/ArticleDelB')" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>
        </span>
        <span class="r">共有数据：<strong>@manuscript.Count</strong> 条</span>
    </div>
    <div class="mt-20">
        <table class="table table-border table-bordered table-hover table-bg table-sort" id="usertable">
            <thead>

                <tr class="text-c">
                    <th width="4%"><input type="checkbox" name="" value=""></th>
                    <th width="5%">序号</th>
                    <th width="30%">文件名</th>
                    <th width="8%">作者名</th>
                    <th width="8%">状态</th>
                    <th width="14%">提交时间</th>
                    <th width="14%">通过时间</th>
                    <th width="8%">审核人</th>
                    <th width="">操作</th>
                </tr>
            </thead>
            <tbody>
                @for (int i = 0; i < manuscript.Count; i++)
                {
                    <tr class="text-c">
                        <td><input type="checkbox" id="articleid" value="@manuscript[i].Id" name="articleChk"></td>
                        <td>@(i + 1)</td>
                        <td><a title="查看文稿" onclick="article_show('文稿信息','/Home/ArticleLook','@manuscript[i].SubmitTime','@manuscript[i].FileName')" href="javascript:;">@manuscript[i].FileName</a></td>
                        <td>@manuscript[i].Author</td>
                        @if (manuscript[i].Statu == "正在审核")
                        {
                            <td class="td-status"><span class="label label-primary radius">@manuscript[i].Statu</span></td>
                        }
                        else if (manuscript[i].Statu == "一审通过")
                        {
                            <td class="td-status"><span class="label label-success radius">@manuscript[i].Statu</span></td>
                        }
                        else if(manuscript[i].Statu == "二审通过")
                        {
                            <td class="td-status"><span class="label label-warning radius">@manuscript[i].Statu</span></td>
                        }
                        else if(manuscript[i].Statu == "销售中")
                        {
                            <td class="td-status"><span class="label label-danger radius">@manuscript[i].Statu</span></td>
                        }
                        <td>@manuscript[i].SubmitTime</td>
                        <td>@manuscript[i].AccessTime</td>
                        <td>@manuscript[i].AccessName</td>
                        <td class="td-manage">
                            @if (manuscript[i].Statu == "正在审核")
                            {
                                <a title="第一次审核" href="javascript:;" onclick="article_check(this,'/Home/ArticleCheck','@manuscript[i].Id')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e0;</i></a>
                            }
                            else if (manuscript[i].Statu == "一审通过")
                            {
                                <a title="第二次审核" href="javascript:;" onclick="article_check_two(this)" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e1;</i></a>
                            }
                            else if (manuscript[i].Statu == "二审通过")
                            {
                                <a title="上架销售" href="javascript:;" onclick="article_check_sale(this)" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6dc;</i></a>
                            }
                            else { }
                            <a title="删除" href="javascript:;" onclick="article_del(this,'/Home/ArticleDel','@manuscript[i].Id')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>
                        </td>
                    </tr>
                 }
            </tbody>
        </table>
    </div>
</div>

<script type="text/javascript">

    //文稿查看
    function article_show(title, url, t, n) {
        var time;
        var nurl;
        $.ajax({
            type: "POST",
            url: url + '?t=' + t,
            async: false,
            dataType: "text",
            success: function (result) {
                time = result;  
                nurl = "https://hupangpang.xyz/ftp/" + time + '/' + n;
                var index = layer.open({
                    type: 2,
                    title: title,
                    content: nurl
                });
                layer.full(index);
            },
            error: function () {
                layer.msg('网络错误，打开失败！', { icon: 5, time: 2000 });
            }
        });
    }

    //文稿删除
    function article_del(obj, url,id) {
        layer.confirm('确认要删除吗？', function (index) {
            $.ajax({
                type: 'POST',
                url: url,
                data: {
                    "articleid": id
                },
                success: function (response) {
                    if (response == "ok") {
                        $(obj).parents("tr").remove();
                        layer.msg('已删除!', { icon: 1, time: 1000 });
                    }
                    else
                        layer.msg('删除失败! ', { icon: 5, time: 3000 });
                },
                error: function (response) {
                    layer.msg('删除失败!', { icon: 5, time: 3000 });
                },
            });
        });
    }

    //文稿批量删除
    function article_batch_del(url) {
        var checkedNum = $("input[name='articleChk']:checked").length;
        if (checkedNum == 0) {
            layer.msg('请选择至少一项！', { icon: 1, time: 2000 });
            return;
        }
        layer.confirm('确定要删除所选项目？', function (index) {
            var checkedList = new Array();
            $("input[name='articleChk']:checked").each(function () {
                checkedList.push($(this).val());
            });
            $.ajax({
                type: "POST",
                url: url,
                data: { 'delitems': checkedList.toString() },
                success: function (result) {
                    if (result == "ok") {
                        $("input[name='articleChk']:checked").each(function () {
                            $(this).parent("tr").remove();
                        });
                        $("[name ='articleChk']:checkbox").attr("checked", false);
                        layer.msg('已删除!', { icon: 1, time: 3000 });
                        window.location.reload();
                    }
                    else
                        layer.msg('存在无法删除的文稿！', { icon: 5, time: 3000 });
                },
                error: function () {
                    layer.msg('删除失败! 请稍后再试', { icon: 5, time: 3000 });
                },
            });
        });
    }


    //文稿审核
    function article_check(obj,aurl,id) {
        var url = aurl + "?id=" + id;
        layer.confirm('第一次审核文稿？', {
            btn: ['一审通过', '不通过', '取消'],
            shade: false,
            closeBtn: 0
        },
            function () {
                $.ajax({
                    type: "POST",
                    url: url,
                    data: { "articlestatu": '一审通过' },
                    success: function (result) {
                        if (result == "ok") {
                            $(obj).parents("tr").find(".td-manage").prepend('<a title="第二次审核" href="javascript:;" onclick="article_check_two(this)" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e1;</i></a>');
                            $(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">一审通过</span>');
                            $(obj).remove();
                            layer.msg('一审通过', { icon: 6, time: 2000 });
                            window.location.reload();
                        }
                        else if (result == "false")
                            layer.msg('审核失败！请稍后再试', { icon: 5, time: 2000 });
                    },
                    error: function () {
                        layer.msg('网络错误！请稍后再试', { icon: 5, time: 2000 });
                    }
                });
            },
            function () {
                layer.msg('未通过', { icon: 6, time: 2000 });
                layer_close();
            });
    }

    //文稿审核2
    function article_check_two(obj) {
        var id = $("#articleid").val();
        var url = "/Home/ArticleCheck" + "?id=" + id;
        //url = "/Home/ArticleCheck";
        layer.confirm('第二次审核文稿？', {
            btn: ['二审通过', '不通过', '取消'],
            shade: false,
            closeBtn: 0
        },
            function () {
                $.ajax({
                    type: "POST",
                    url: url,
                    data: { "articlestatu": '二审通过' },
                    success: function (result) {
                        if (result == "ok") {
                            $(obj).parents("tr").find(".td-manage").prepend('<a title="上架销售" href="javascript:;" onclick="article_check_sale(this)" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6dc;</i></a>');
                            $(obj).parents("tr").find(".td-status").html('<span class="label label-warning radius">二审通过</span>');
                            $(obj).remove();
                            layer.msg('二审通过', { icon: 6, time: 2000 });
                            window.location.reload();
                        }
                        else if (result == "false")
                            layer.msg('审核失败！请稍后再试', { icon: 5, time: 2000 });
                    },
                    error: function () {
                        layer.msg('网络错误！请稍后再试', { icon: 5, time: 2000 });
                    }
                });
            },
            function () {
                layer.msg('未通过', { icon: 6, time: 2000 });
                layer_close();
            });
    }


    //上架销售
    function article_check_sale(obj) {
        var id = $("#articleid").val();
        var url = "/Home/ArticleCheck" + "?id=" + id;
        //url = "/Home/ArticleCheck";
        layer.confirm('上架销售？', {
            btn: ['直接通过', '添加图书信息', '取消'],
            shade: false,
            closeBtn: 0
        },
            function () {
                $.ajax({
                    type: "POST",
                    url: url,
                    data: { "articlestatu": '销售中' },
                    success: function (result) {
                        if (result == "ok") {
                            $(obj).parents("tr").find(".td-status").html('<span class="label label-danger radius">销售中</span>');
                            $(obj).remove();
                            layer.msg('该书已在销售中', { icon: 6, time: 2000 });
                            window.location.reload();
                        }
                        else if (result == "false")
                            layer.msg('通过失败！请稍后再试', { icon: 5, time: 2000 });
                    },
                    error: function () {
                        layer.msg('网络错误！请稍后再试', { icon: 5, time: 2000 });
                    }
                });
            },
            function () {
                var index = layer.open({
                    type: 2,
                    title: '添加图书信息',
                    content: '/Home/BookAdd'
                });
                layer.full(index);
                layer.msg("已添加");
                layer_close();
            });
    }


    //文稿下载
    function article_download() {

    }


</script>